#include "const/oPreDefine.h"
#include "misc/oKeyboard.h"

bool oKeyboard::_newKeyState[MAX_KEY] = {0};
bool oKeyboard::_oldKeyState[MAX_KEY] = {0};

void oKeyboard::updateKey( uint8 key, bool isDown )
{
	_oldKeyState[key] = _newKeyState[key];
	_newKeyState[key] = isDown;
}

bool oKeyboard::isKeyDown( uint8 key )
{
	return !_oldKeyState[key] && _newKeyState[key];
}

bool oKeyboard::isKeyUp( uint8 key )
{
	return _oldKeyState[key] && !_newKeyState[key];
}

bool oKeyboard::isKeyPressed( uint8 key )
{
	return _newKeyState[key];
}

void oKeyboard::clear()
{
	memset(_oldKeyState, 0, sizeof(bool)*MAX_KEY);
	memset(_newKeyState, 0, sizeof(bool)*MAX_KEY);
}
